clear
cd "\\file\Userss$\sho88\Home\Desktop\World Development\FinalCodes\"
import delimited "data_sorted.csv"
gen r = pcc
gen seR = sepcc
gen varR = sepcc^2

*---------------------------------------------------------------*
*   TABLE 3: Descriptive Statistics for tstats, df, and PCCs      *
*---------------------------------------------------------------*
log using EstimationResults\Table03.log
summ tstat df pcc, detail
summ pcc if iv == 1
regress pcc if iv ==1
log close

*--------------------------------------------------------------------------------*
*   FIGURE 1: Histograms of tstat and PCC                                        *
*--------------------------------------------------------------------------------*

preserve
drop if abs(tstat) > 10
histogram tstat, bin(30)
graph save EstimationResults\Figure01_histogram(tstat), replace
restore

gen dis="(1)t<-2" if tstat<-2
replace dis="(2)-2<=t<=2" if tstat>=-2 & tstat<=2
replace dis="(3)t>2" if tstat>2
tab dis

histogram pcc, bin(30) 
graph save EstimationResults\Figure01_histogram(pcc), replace


*---------------------------------------------------------------*
*   TABLE 6: Descriptive Statistics                               *
*---------------------------------------------------------------*

log using EstimationResults\Table06.log
summ fdigdp fdilog fdiother entretype1 entretype2 entretype3 entreother  ///
oecd nonoecd mixedcountry  crosssection panelfe panelnofe lagdv busenviron iv pubyear ///
 english journal notjournal
log close

*---------------------------------------------------------------*
*   FIGURE 2: Forrest Plot                                        *
*---------------------------------------------------------------*

metareg r seR , wsse(seR)
scalar tau2 =  e(tau2)
gen revarR = varR + tau2
gen reweightR = 1/revarR
gen rR = r*reweightR
collapse (sum) rR reweightR, by (id)
gen avgR = rR/reweightR
gen avgsterrR = sqrt(1/reweightR)
sort id
metan avgR avgsterrR, random lcols(id) nobox nowt xlabel(-1, 1) force
metan avgR avgsterrR, random lcols(id) nobox xlabel(-1, 1) force
graph save  EstimationResults\Figure02_ForrestPlot.gph, replace



